home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 1
/
Nebula One.iso
/
Utilities
/
Converters
/
Convert_PICT
/
Convert PICT.app
/
CommentedPSCode
/
Bitmaps
< prev
next >
Wrap
Text File
|
1995-06-12
|
8KB
|
336 lines
%BEGIN Bitmaps
% Copyright (C) 1993 David John Burrowes
% Distributed under terms of GNU General Public License.
% See COPYING.text in Convert PICT's CommentedPSCode for a copy
%%%%%%%%%%%%%
% Define lengh of a run, and the byte which is repeated that many times
%%%%%%%%%%%%%
/lengthByte 1 string def
/runByte 1 string def
%%%%%%%%%%%%%
% Name: unpackbytes
% Syntax: - unpackbytes -
% About: This unpacks packed hex data into a binary string. Data format
% is identical to PS level 2 RLE and Mac PackBits (plus
% terminating 0x80). Each chunk of data starts with a 'length'
% byte. If it is < 128 use that number of following bytes (plus
% one) literally. If it is > 128, next byte should be used
% 257-length times. Note: if 128 ends up in data, we don't deal
% properly (it shouldn't though)
%%%%%%%%%%%%%
/unpackbytes
{
%
% Get a byte which tells us how to extract the next chunk of data
%
/thelength
currentfile lengthByte readhexstring pop
0 get
def
%
% If length < 128, copy that number of bytes+1 in litterally
% Otherwise, copy next byte 257-length number of times
%
thelength 128 lt
{
/dataString thelength 1 add string def
currentfile dataString readhexstring pop
}
{
/runlength 257 thelength sub def
/runString runlength string def
currentfile runByte readhexstring pop pop
0 1 runlength 1 sub
{ runString exch runByte putinterval }
for
runString
}
ifelse
}
def
%%%%%%%%%%%%%
% Name: bitmap [0090, 0091, 0097, 0098 (Pict1 & subset pict2)]
% Syntax: colordat bits mode llx lly width height sourcewW sourceH
% bool [regiondata] bool bitmap -
% About: Display a B&W bitmap. If bool is true, clipping region data
% follows. The width & height of the image, and the rect (origin,
% width, height) to display it follow. Mac drawing mode, bitdepth,
% then info for a colorspace definition. Final args are redundant.
% (both this and colorbitmap have same args this way)
%%%%%%%%%%%%%
/bitmap
{
gsave
% use flag on stack
{
initclip
regionBounds
clip
/numShapes exch def
numShapes 0 gt
{
numShapes
regionPath
clip
}
if
}
if
/isPacked exch def
/sourceHeight exch def
/sourceWidth exch def
/destHeight exch def
/destWidth exch def
/boty exch def
/botx exch def
/mode exch def
/bitDepth exch def % unused
/colordata exch def % "
/numcolors exch def % "
%
% Compute a string with length equal to the number of bytes used
% per scaline. That number is (bits-per-scaline /8), & wrap up to
% next whole byte.
%
/scanString sourceWidth 8 div ceiling cvi string def
botx boty destHeight add translate
destWidth destHeight scale
%
% With B&W bitmaps, it's easy to support the two Or transfer modes
% Check for the two Or modes, and use proper imageMask.
% Otherwise, default to doing a srcCpy
%
0 setgray
PSlevel 1 eq
{
mode /srcOr eq
mode /notSrcOr eq
or
{
%
% Compute a true or false value for imagemask using mode
%
sourceWidth sourceHeight mode /notSrcOr eq
[sourceWidth 0 0 sourceHeight 0 sourceHeight]
isPacked true eq
{ {unpackbytes} }
{ {currentfile scanString readhexstring pop} }
ifelse
imagemask
}
{
%
% Do a copy mode.
%
sourceWidth sourceHeight 1
[sourceWidth 0 0 sourceHeight 0 sourceHeight]
isPacked true eq
{ {unpackbytes} }
{ {currentfile scanString readhexstring pop} }
ifelse
image
}
ifelse
%
% Remove the trailing end-of-line80 or eol>
%
isPacked false eq
{ 2 { currentfile read pop pop } repeat }
{ 4 { currentfile read pop pop } repeat }
ifelse
}
{
/DeviceGray setcolorspace
%
% Build the dict. parameter for the PS2 image or imageMask op.
%
/imageParams 7 dict def
imageParams begin
/ImageType 1 def
/Width sourceWidth def
/Height sourceHeight def
/BitsPerComponent 1 def
/Decode mode /notSrcOr eq
{ [ 1 0 ] } { [ 0 1 ] } ifelse def
/ImageMatrix [sourceWidth 0 0 sourceHeight
0 sourceHeight] def
/DataSource isPacked true eq
{ currentfile /ASCIIHexDecode filter
/RunLengthDecode filter}
{ currentfile /ASCIIHexDecode filter}
ifelse
def
end
mode /srcOr eq
mode /notSrcOr eq
or
{ imageParams imagemask }
{ imageParams image }
ifelse
}
ifelse
grestore
}
def
%%%%%%%%%%%%%
% Name: colorbitmap [0090, 0091, 0097, 0098 (for pict2 images)]
% Syntax: colordat bits mode llx lly width height sourcewW sourceH
% bool [regiondata] bool colorbitmap -
% About: Display a bitmap. If bool is true, clipping region data follows.
% The width and height of the image, and the rect (origin, width,
% height) to display it follow. Mac drawing mode, bitdepth, then
% info for a colorspace definition. The bit data follows.
%%%%%%%%%%%%%
/colorbitmap
{
gsave
% use flag on stack
{
initclip
regionBounds
clip
/numShapes exch def
numShapes 0 gt
{
numShapes
regionPath
clip
}
if
}
if
/isPacked exch def
/sourceHeight exch def
/sourceWidth exch def
/destHeight exch def
/destWidth exch def
/boty exch def
/botx exch def
/mode exch def
/sampleDepth exch def
/colordata exch def
/numcolors exch def
%
% Move to the right location and scale coordinate space properly.
%
botx boty destHeight add translate
destWidth destHeight scale
PSlevel 1 eq
{
%
% Compute string with space for full scanline of image data:
% Use bits per scanline, divide by 8, round up to whole byte.
%
/scanString sourceWidth sampleDepth mul 8 div
ceiling cvi string def
sourceWidth sourceHeight sampleDepth
[sourceWidth 0 0 sourceHeight 0 sourceHeight]
isPacked true eq
{ {unpackbytes} }
{ {currentfile scanString readhexstring pop} }
ifelse
image
%
% Remove trailing end-of-line80 or eol>
%
isPacked false eq
{ 2 { currentfile read pop pop } repeat }
{ 4 { currentfile read pop pop } repeat }
ifelse
}
{
[ /Indexed /DeviceRGB numcolors colordata] setcolorspace
%
% Build the dict. parameter to the PS level 2 image operator
%
/imageParams 7 dict def
imageParams begin
/ImageType 1 def
/Width sourceWidth def
/Height sourceHeight def
/BitsPerComponent sampleDepth def
/Decode [ 0 2 sampleDepth exp 1 sub ] def
/ImageMatrix [sourceWidth 0 0 sourceHeight 0
sourceHeight] def
/DataSource isPacked true eq
{ currentfile /ASCIIHexDecode filter
/RunLengthDecode filter}
{ currentfile /ASCIIHexDecode filter}
ifelse
def
end
imageParams image
}
ifelse
grestore
}
def
%%%%%%%%%%%%%
% Name: 24bitBitmap [009A, 009B]
% Syntax: mode llx lly width height sourcewW sourceH
% [regiondata] bool colorbitmap -
% About: This displays a bitmap. It differs from bitmap and colorbitmap in that
% the bitmap it is to display is not black and white and requires no color table.
% It uses only literal 24bit color values for the image. args are:
% an optional region definition, the initial width and height, the requested
% destination width and height, the x and y coord of the lower left, and the mac
% drawing mode
%%%%%%%%%%%%%
/24bitBitmap
{
gsave
% use flag on stack
{
initclip
regionBounds
clip
/numShapes exch def
numShapes 0 gt
{
numShapes
regionPath
clip
}
if
}
if
/isPacked exch def
/sourceHeight exch def
/sourceWidth exch def
/destHeight exch def
/destWidth exch def
/boty exch def
/botx exch def
/mode exch def
%
% Move to the right location and scale coordinate space properly.
%
botx boty destHeight add translate
destWidth destHeight scale
%
% Compute string with space for full scanline of image data (convert pixels to bytes)
%
/scanString sourceWidth 3 mul string def
sourceWidth sourceHeight 8
[sourceWidth 0 0 sourceHeight 0 sourceHeight]
isPacked true eq
{ {unpackbytes} }
{ {currentfile scanString readhexstring pop} }
ifelse
false 3
colorimage
grestore
}
def
%END Bitmaps